***************************************
* BANGLADESH data: generate variables *
***************************************

/*
This do file generates variables for the following four datasets:
1. Data_Covid_BD_wave_1_original.dta
2. Data_Covid_BD_wave_2_original.dta
3. Data_Covid_BD_wave_1_full_sample_orginal.dta
4. Data_attrition_BD_original.dta
*/


********************************************************************************************
**** Generating variable for Wave 1: Data_Covid_BD_wave_1_original.dta
********************************************************************************************
// import the following data of Bangladesh: Data_Covid_BD_wave_1_original.dta
// label variable
label variable Upazila "Name of the upazila"
label variable UNION_CODE "Name of the union"
label variable treat "Treatment (1=SMS only, 2=Call only, 3=Both SMS & Call)"


//Generate treatment dummies
gen treat1=0
replace treat1=1 if treat==1
label variable treat1 "Household assigned to treatment 1 (Text only)(=1) or not (=0)"


gen treat2=0
replace treat2=1 if treat==2
label variable treat2 "Household assigned to treatment 2 (Call only)(=1) or not (=0)"

gen treat3=0
replace treat3=1 if treat==3
label variable treat3 "Household assigned to treatment 3 (Both Text & Call)(=1) or not (=0)"


** Describe variable related to food security
label variable Q6_1 "Worried you wouldn't have food"
label variable Q6_2 "You were unable to eat healthy and nutritious food"
label variable Q6_3 "You ate only a few kinds of foods"
label variable Q6_4 "You had to skip a meal"
label variable Q6_5 "You ate less than you thought you should"
label variable Q6_6 "Your household ran out of food"
label variable Q6_7 "You were hungry but did not eat"
label variable Q6_8 "You went without eating for a whole day"

** To genreate dummy of food insecurity
egen food=rowtotal(Q6_1 Q6_2 Q6_3 Q6_4 Q6_5 Q6_6 Q6_7 Q6_8)
label variable food "FIES scale (0-8)"
gen insec = 1 if food>0
replace insec = 0 if insec ==.
label variable insec "Whether household is food insecure (=1) or food secure (=0)"


//Generate worried about finances and health
gen finance_worry=0
replace finance_worry=1 if Q2_3_worry_finance==2 | Q2_3_worry_finance==3  // need to check the dummy creation, it shoud be same as the variable "health variable"
label variable finance_worry "Whether very worried about finances (=1) or not (=0)"

gen health_worry=0
replace health_worry=1 if Q2_1_health_worry==2 | Q2_1_health_worry==3  // need to check the dummy creation, it shoud be same as the variable "health variable"
label variable health_worry "Whether very worried about family health (=1) or not (=0)"

//Generate log income
gen log_income=ln(Monthly_income)  // log of monthly income in BDT (Bangladesh taka)
label variable log_income "Log of monthly income"


//Generate occupation catergorical variable
gen occupation=0
replace occupation=1 if (Q5_1==1)
replace occupation=2 if (Q5_1==2|Q5_1==3)
replace occupation=3 if (Q5_1==4|Q5_1==7)

label define occupation 0 "Professional" 1 "Farmer" 2 "Labourer" 3 "Selfemployed", replace
label values occupation occupation
label variable occupation "Occupation of the main earner of a household"

//Generate four seperate dummies for occupation, used in summary statistics table
gen professional=0
replace professional=1 if occupation==0
label variable professional "=1 if primary occupation of the main earner is public/private job, and 0=others"

gen farmer1=0
replace farmer1=1 if occupation==1
label variable farmer1 "=1 if primary occupation of the main earner is farming, and 0=others"

gen laborer1=0
replace laborer1=1 if occupation==2
label variable laborer1 "=1 if primary occupation of the earner is farm laborer/day laborer, and 0=others"

gen selfemployed=0
replace selfemployed=1 if occupation==3
label variable selfemployed "=1 if primary occupation of the main earner is business/others, and 0=others"


********************************************************************************************
** Bangladesh Wave 1  Compliance questions (dummy variable constructions)
********************************************************************************************
// Generating compliance dummy
gen wash2=0
replace wash2=1 if Q4_1_wash>=3
label variable wash2 "Washed hands 5 times in a day at least on 3 days in past week (=1) or not (=0)"

gen avoid_physical2=0
replace avoid_physical2=1 if Q4_2_physical_contact>=3
label variable avoid_physical2 "Did not have any close contact with outsiders at least on 3 days (=1) or not (=0)"

gen market2=0
replace market2=1 if Q3_2T_market<=2
label variable market2 "Went to the market at most on 2 days in the past week (=1) or not (=0)"

gen doctor2=0
replace doctor2=1 if Q3_3T_doctor<=2
label variable doctor2 "Went to the doctor at most on 2 days in the past week (=1) or not (=0)"

gen entertainment2=0
replace entertainment2=1 if  Q3_4T_entertainment<=2
label variable entertainment2 "Went out for entertainment purpose at most on 2 days in past week (=1) or not (=0)"

gen religious2 =0
replace religious2 =1 if  Q3_5T_religious<=2
label variable religious2 "Went out for religious purpose at most on 2 days in the past week (=1) or not (=0)"

********************************************************************************************
label variable Gender_res "=1 if Male and 0= Female"
label variable rel_islam "1=Respondent is muslim and 0 = others"
label variable nmember "Number of family members"
label variable age_respondent "Age of the repondent (in years)"
label variable edu_respondent "Year of schooling of the respondent (in years)"
label variable media_exp "Whether household has TV or radio (=1) or not (=0)"
label variable Monthly_income "Monthly income of the household (BDT/month)"
********************************************************************************************

** Generating variables related awarness
egen tot_ans=rowtotal(Q1_1_1_wash Q1_1_2_Cover_mouth Q1_1_3_distance Q1_1_4_handshake Q1_1_5_healthy)
label variable tot_ans "Number of correct responses about awarness (on a scale between 0 and 5)"

gen all_ans=0   // to generate the dummy for complete awarness
replace all_ans=1 if tot_ans==5
label variable all_ans "=1 if the respondent mentioned all five rules correctly and 0 otherwise"

//Generate the compliance index, so that the control group has mean 0 and SD 1
egen comply=rowtotal(market2 doctor2 entertainment2 religious2 wash2 avoid_physical2)
replace comply=comply/6
label variable comply "Compliance index (between 0 and 1)"

egen comp_control=mean(comply) if treat==1
replace comp_control = comp_control[_n-1] if comp_control >= .

egen comp_con_stdv=sd(comply) if treat==1
replace comp_con_stdv = comp_con_stdv[_n-1] if comp_con_stdv >= .

gen compidx=((comply-comp_control)/comp_con_stdv)
label variable compidx "Compliance index (standardized)"

drop comp_control comp_con_stdv

//Generate parsimonious compliance index, for robustness check
egen comply_robust=rowtotal(wash2 avoid_physical2)
replace comply_robust=comply_robust/2
label variable comply_robust "Compliance index (0 to 1) using hand washing and contact only"

egen comp_control=mean(comply_robust) if treat==1
replace comp_control = comp_control[_n-1] if comp_control >= .

egen comp_con_stdv=sd(comply_robust) if treat==1
replace comp_con_stdv = comp_con_stdv[_n-1] if comp_con_stdv >= .

gen compidx_robust=((comply_robust-comp_control)/comp_con_stdv)
label variable compidx_robust "Compliance index (standardized) using hand washing and contact only"

drop comp_control comp_con_stdv comply_robust


//save it as Data_Covid_BD_wave_1.dta
********************************************************************************************





********************************************************************************************
** Generating variable for Wave 1 (Full Sample): Data_Covid_BD_wave_1_full_sample_orginal.dta
********************************************************************************************
// import the following data of Bangladesh: Data_Covid_BD_wave_1_full_sample_orginal.dta
// label variable
label variable Upazila "Name of the upazila"
label variable UNION_CODE "Name of the union"
label variable treat "Treatment (1=SMS only, 2=Call only, 3=Both SMS & Call)"


//Generate treatment dummies
gen treat1=0
replace treat1=1 if treat==1
label variable treat1 "Household assigned to treatment 1 (Text only)(=1) or not (=0)"


gen treat2=0
replace treat2=1 if treat==2
label variable treat2 "Household assigned to treatment 2 (Call only)(=1) or not (=0)"

gen treat3=0
replace treat3=1 if treat==3
label variable treat3 "Household assigned to treatment 3 (Both Text & Call)(=1) or not (=0)"


** Describe variable related to food security
label variable Q6_1 "Worried you wouldn't have food"
label variable Q6_2 "You were unable to eat healthy and nutritious food"
label variable Q6_3 "You ate only a few kinds of foods"
label variable Q6_4 "You had to skip a meal"
label variable Q6_5 "You ate less than you thought you should"
label variable Q6_6 "Your household ran out of food"
label variable Q6_7 "You were hungry but did not eat"
label variable Q6_8 "You went without eating for a whole day"

** To genreate dummy of food insecurity
egen food=rowtotal(Q6_1 Q6_2 Q6_3 Q6_4 Q6_5 Q6_6 Q6_7 Q6_8)
label variable food "FIES scale (0-8)"
gen insec = 1 if food>0
replace insec = 0 if insec ==.
label variable insec "Whether household is food insecure (=1) or food secure (=0)"


//Generate worried about finances and health
gen finance_worry=0
replace finance_worry=1 if Q2_3_worry_finance==2 | Q2_3_worry_finance==3  // need to check the dummy creation, it shoud be same as the variable "health variable"
label variable finance_worry "Whether very worried about finances (=1) or not (=0)"

gen health_worry=0
replace health_worry=1 if Q2_1_health_worry==2 | Q2_1_health_worry==3  // need to check the dummy creation, it shoud be same as the variable "health variable"
label variable health_worry "Whether very worried about family health (=1) or not (=0)"

//Generate log income
gen log_income=ln(Monthly_income)  // log of monthly income in BDT (Bangladesh taka)
label variable log_income "Log of monthly income"



// Generate four categories for occupation
gen occupation=0
replace occupation=1 if (Q5_1==1)
replace occupation=2 if (Q5_1==2|Q5_1==3)
replace occupation=3 if (Q5_1==4|Q5_1==7)

label define occupation 0 "Professional" 1 "Farmer" 2 "Labourer" 3 "Selfemployed", replace
label values occupation occupation
label variable occupation "Occupation of the main earner of a household"

********************************************************************************************
** Bangladesh Wave 1  Compliance questions (dummy variable constructions)
********************************************************************************************
// Generating compliance dummy
gen wash2=0
replace wash2=1 if Q4_1_wash>=3
label variable wash2 "Washed hands 5 times in a day at least on 3 days in past week (=1) or not (=0)"

gen avoid_physical2=0
replace avoid_physical2=1 if Q4_2_physical_contact>=3
label variable avoid_physical2 "Did not have any close contact with outsiders at least on 3 days (=1) or not (=0)"

gen market2=0
replace market2=1 if Q3_2T_market<=2
label variable market2 "Went to the market at most on 2 days in the past week (=1) or not (=0)"

gen doctor2=0
replace doctor2=1 if Q3_3T_doctor<=2
label variable doctor2 "Went to the doctor at most on 2 days in the past week (=1) or not (=0)"

gen entertainment2=0
replace entertainment2=1 if  Q3_4T_entertainment<=2
label variable entertainment2 "Went out for entertainment purpose at most on 2 days in past week (=1) or not (=0)"

gen religious2 =0
replace religious2 =1 if  Q3_5T_religious<=2
label variable religious2 "Went out for religious purpose at most on 2 days in the past week (=1) or not (=0)"

********************************************************************************************
label variable Gender_res "=1 if Male and 0= Female"
label variable rel_islam "1=Respondent is muslim and 0 = others"
label variable nmember "Number of family members"
label variable age_respondent "Age of the repondent (in years)"
label variable edu_respondent "Year of schooling of the respondent (in years)"
label variable media_exp "Whether household has TV or radio (=1) or not (=0)"
label variable Monthly_income "Monthly income of the household (BDT/month)"
********************************************************************************************

** Generating variables related awarness
egen tot_ans=rowtotal(Q1_1_1_wash Q1_1_2_Cover_mouth Q1_1_3_distance Q1_1_4_handshake Q1_1_5_healthy)
label variable tot_ans "Number of correct responses about awarness (on a scale between 0 and 5)"

gen all_ans=0   // to generate the dummy for complete awarness
replace all_ans=1 if tot_ans==5
label variable all_ans "=1 if the respondent mentioned all five rules correctly and 0 otherwise"


//Generate the compliance index, so that the control group has mean 0 and SD 1
egen comply=rowtotal(market2 doctor2 entertainment2 religious2 wash2 avoid_physical2)
replace comply=comply/6
label variable comply "Compliance index (between 0 and 1)"

egen comp_control=mean(comply) if treat==1
replace comp_control = comp_control[_n-1] if comp_control >= .

egen comp_con_stdv=sd(comply) if treat==1
replace comp_con_stdv = comp_con_stdv[_n-1] if comp_con_stdv >= .

gen compidx=((comply-comp_control)/comp_con_stdv)
label variable compidx "Compliance index (standardized)"

drop comp_control comp_con_stdv


//Save it as Data_Covid_BD_wave_1_full_sample.dta
********************************************************************************************











********************************************************************************************
**** Generating variable for Wave 2: Data_Covid_BD_wave_2_original.dta
********************************************************************************************
//Import the following data of Bangladesh: Data_Covid_BD_wave_2_original.dta


*****************************************************************************
label variable Gender_res "=1 if Male and 0= Female"
label variable rel_islam "1=Respondent is muslim and 0 = others"
label variable nmember "Number of family members"
label variable age_respondent "Age of the repondent (in years)"
label variable edu_respondent "Year of schooling of the respondent (in years)"
label variable media_exp "Whether household has TV or radio (=1) or not (=0)"
label variable Monthly_income "Monthly income of the household (BDT/month)"
*****************************************************************************


//Generate treatment dummies
gen treat1=0
replace treat1=1 if treat==1
label variable treat1 "Household assigned to treatment 1 (Text only)(=1) or not (=0)"

gen treat2=0
replace treat2=1 if treat==2
label variable treat2 "Household assigned to treatment 2 (Call only)(=1) or not (=0)"

gen treat3=0
replace treat3=1 if treat==3
label variable treat3 "Household assigned to treatment 3 (Both Text & Call)(=1) or not (=0)"

//Generate worried about finances and health
gen finance_worry=0
replace finance_worry=1 if Q2_3_worry_finance==2 | Q2_3_worry_finance==3  // need to check the dummy creation, it shoud be same as the variable "health variable"
label variable finance_worry "Whether very worried about finances (=1) or not (=0)"

gen health_worry=0
replace health_worry=1 if Q2_1_health_worry==2 | Q2_1_health_worry==3  // need to check the dummy creation, it shoud be same as the variable "health variable"
label variable health_worry "Whether very worried about family health (=1) or not (=0)"

//Generate log income
gen log_income=ln(Monthly_income)  // log of monthly income in BDT (Bangladesh taka)
label variable log_income "Log of monthly income"

// Generate four categories for occupation
gen occupation=0
replace occupation=1 if (Q5_1==1)
replace occupation=2 if (Q5_1==2|Q5_1==3)
replace occupation=3 if (Q5_1==4|Q5_1==7)

label define occupation 0 "Professional" 1 "Farmer" 2 "Labourer" 3 "Selfemployed", replace
label values occupation occupation
label variable occupation "Occupation of the main earner of a household"



** Variable related to food security
label variable Q5_1_2nd "Worried you wouldn't have food"
label variable Q5_2_2nd "You were unable to eat healthy and nutritious food"
label variable Q5_3_2nd "You ate only a few kinds of foods"
label variable Q5_4_2nd "You had to skip a meal"
label variable Q5_5_2nd "You ate less than you thought you should"
label variable Q5_6_2nd "Your household ran out of food"
label variable Q5_7_2nd "You were hungry but did not eat"
label variable Q5_8_2nd "You went without eating for a whole day"


** To genreate dummy of food insecurity
egen food2=rowtotal(Q5_1_2nd Q5_2_2nd Q5_3_2nd Q5_4_2nd Q5_5_2nd Q5_6_2nd Q5_7_2nd Q5_8_2nd)
label variable food2 "FIES scale (0-8)"


gen mild=1 if Q5_1_2nd==1| Q5_2_2nd==1| Q5_3_2nd==1
gen mod=1 if Q5_4_2nd==1| Q5_5_2nd==1| Q5_6_2nd==1
gen sev=1 if Q5_7_2nd==1| Q5_8_2nd==1

replace mod=0 if sev==1
replace mild=0 if sev==1
replace mild=0 if mod==1

replace sev=0 if sev==.
replace mod=0 if mod==.
replace mild=0 if mild==.

gen food_sec2=0
replace food_sec2=1 if mild==1
replace food_sec2=2 if mod==1
replace food_sec2=3 if sev==1
label define food_sec2 0 "No insecurity" 1 "Mild insecurity" 2 "Moderate insecurity" 3 "Severe insecurity", add
label values food_sec2 food_sec2
label variable food_sec2 "Food insecurity of the household"
drop mild mod sev

gen insec2 = 1 if food2>0
replace insec2 = 0 if insec2 ==.
label variable insec2 "Whether household is food insecure (=1) or food secure (=0)"


*************************************************************
*** Creating dummy for compliance in the Second Endline (Wave 2)
*************************************************************
gen Q12_1=0
replace Q12_1=1 if Q12a>=3
label variable Q12_1 "Washed hands 5 times in a day at least on 3 days in past week (=1) or not (=0)"

gen Q12_2=0
replace Q12_2=1 if Q12b>=3
label variable Q12_2 "Did not leave home at least on 3 separate days in past week (=1) or not (=0)"

gen Q12_3=0
replace Q12_3=1 if Q12c>=3
label variable Q12_3 "Did not go out for religious purpose at least on 3 days (=1) or not (=0)"

gen Q12_4=0
replace Q12_4=1 if Q12d>=3
label variable Q12_4 "Maintained a 2 arms distance from others at least on 3 days (=1) or not (=0)"

gen Q12_5=0
replace Q12_5=1 if Q12e>=3
label variable Q12_5 "Used a mask when they were outside at least on 3 days (=1) or not (=0)"

gen Q12_6=0
replace Q12_6=1 if Q12f>=3
label variable Q12_6 "Always sneezed in a handkerchief or in elbows at least on 3 days (=1) or not (=0)"

gen Q12_7=0
replace Q12_7=1 if Q12g>=3
label variable Q12_7 "Did not have any close contact with outsiders at least on 3 days (=1) or not (=0)"




// generate dummy for household chores increased due to covid 19
gen hhchore=0
replace hhchore=1 if Q22<4
label variable hhchore "Whether household chores increased (=1) or at least someone helps(=0)"


//Generate the compliance index, so that the control group has mean 0 and SD 1
egen comply=rowtotal(Q12_1 Q12_2 Q12_3 Q12_4 Q12_5 Q12_6 Q12_7)
replace comply=comply/7
label variable comply "Compliance index (between 0 and 1)"

egen comp_control=mean(comply) if treat==1
replace comp_control = comp_control[_n-1] if comp_control >= .

egen comp_con_stdv=sd(comply) if treat==1
replace comp_con_stdv = comp_con_stdv[_n-1] if comp_con_stdv >= .

gen compidx=((comply-comp_control)/comp_con_stdv)
label variable compidx "Compliance index (standardized)"

drop comp_control comp_con_stdv


//Generate parsimonious compliance index, for robustness check
egen comply_robust=rowtotal(Q12_1 Q12_4 Q12_6 Q12_7)
replace comply_robust=comply_robust/4
label variable comply_robust "Compliance index (0-1) with hand wash, contact, social distancing, sneeze"

egen comp_control=mean(comply_robust) if treat==1
replace comp_control = comp_control[_n-1] if comp_control >= .

egen comp_con_stdv=sd(comply_robust) if treat==1
replace comp_con_stdv = comp_con_stdv[_n-1] if comp_con_stdv >= .

gen compidx_robust_w2=((comply_robust-comp_control)/comp_con_stdv)
label variable compidx_robust_w2 "Compliance index (standardized) with hand wash, contact, social distancing, sneeze"

drop comp_control comp_con_stdv comply_robust


//Save it as Data_Covid_BD_wave_2.dta
***************************************************************************************************************************








********************************************************************************************
**** Generating variable for attrition: Data_attrition_BD_original.dta
********************************************************************************************
// import the following data of Bangladesh: Data_attrition_BD_original.dta

//Generate treatment dummies
gen treat1=0
replace treat1=1 if treat==1
label variable treat1 "Household assigned to treatment 1 (Text only)(=1) or not (=0)"


gen treat2=0
replace treat2=1 if treat==2
label variable treat2 "Household assigned to treatment 2 (Call only)(=1) or not (=0)"

gen treat3=0
replace treat3=1 if treat==3
label variable treat3 "Household assigned to treatment 3 (Both Text & Call)(=1) or not (=0)"

     

*****************************************************************************
label variable gender "=1 if Male and 0= Female"
label variable religion "1=Respondent is muslim and 0 = others"
label variable nmember "Number of family members"
label variable age "Age of the repondent (in years)"
label variable edu "Year of schooling of the respondent (in years)"
label variable income "Monthly income of the household (BDT/month)"
*****************************************************************************


//Generate log income
gen log_income=ln(income)  // log of monthly income in BDT (Bangladesh taka)
label variable log_income "Log of monthly income"

// Generate four categories for occupation
gen occupation=0
replace occupation=1 if (Q5_1==1)
replace occupation=2 if (Q5_1==2|Q5_1==3)
replace occupation=3 if (Q5_1==4|Q5_1==7)

label define occupation 0 "Professional" 1 "Farmer" 2 "Labourer" 3 "Selfemployed", replace
label values occupation occupation
label variable occupation "Occupation of the main earner of a household"

// generate four dummies for occupation
gen professional=0
replace professional=1 if occupation==0
label variable professional "=1 if primary occupation of the main earner is public/private job, and 0=others"

gen farmer=0
replace farmer=1 if occupation==1
label variable farmer "=1 if primary occupation of the main earner is farming, and 0=others"

gen laborer=0
replace laborer=1 if occupation==2
label variable laborer "=1 if primary occupation of the earner is farm laborer/day laborer, and 0=others"

gen selfemployed=0
replace selfemployed=1 if occupation==3
label variable selfemployed "=1 if primary occupation of the main earner is business/others, and 0=others"


//Save it as Data_attrition_BD.dta
********************************************************************************

